﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace King.Box.Utils
{
    public abstract class SingletonBase<T> where T : new()
    {
        #region Static Field
        private static T s_Instance = new T();
        private static readonly object s_lock = new object();
        #endregion

        #region Static
        public static T Instance
        {
            get
            {
                return s_Instance;
            }
        }

        public static void Initialize(T instance)
        {
            //多线程下会出现问题，需要加 s_lock 后台程序并发小因此暂时不加
            s_Instance = instance;
        }

        public static void Reset()
        {
            s_Instance = default(T);
        }
        #endregion
    }
}
